<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <jsp:include page="../common/header.jsp" />
    <script type="text/javascript">
        function save() {
            digit = /^[0-9]*$/;
            $save = $("input[name=save]");
            $save.bind("click", function () {
                if ($.trim($("#bianHao").val()) == "") {
                    $(".inputStyle").css({border: ""});
                    $("#bianHao").css({border: "solid 2px #f00"});
                } else if ($.trim($("#year").val()) == "") {
                    $(".inputStyle").css({border: ""});
                    $("#year").css({border: "solid 2px #f00"});

                }
                else if (!digit.test($("#year").val())) {
                    $(".inputStyle").css({border: ""});
                    $("#year").css({border: "solid 2px #f00"});
                    $(".ErrorStyle").empty();
                    $("#yearError").text("只能是数字");

                }
                else if ($.trim($("#classID").val()) == "") {
                    $(".inputStyle").css({border: ""});
                    $("#classID").css({border: "solid 2px #f00"});

                }
                else if (!digit.test($("#classID").val())) {
                    $(".inputStyle").css({border: ""});
                    $("#classID").css({border: "solid 2px #f00"});
                    $(".ErrorStyle").empty();
                    $("#classIDError").text("只能是数字");

                }
                else {
                    $("#form1").submit();
                }

            });
        }
        function autoExec() {
            var $autoExec = $("input.autoExec");
            $autoExec.bind("click", function () {
                $.ajax(
                        {
                            type: "post",
                            url: "autoExecGradeBh.action",
                            dataType: "json",
                            success: function (data) {
                                var d = eval("(" + data + ")");
                                $("#bianHao").attr("value", "" + d.bianHao + "");
                            },
                            error: function () {
                                alert("系统异常，请稍后重试！");
                            }
                        }
                );
            });
        }
        $(function () {
            $(".button").button();
            $("#selectDeleteBtn").button();
            autoExec();
            save();
            $("#dialog").dialog({
                autoOpen: false,
                width: 400,
                buttons: [{
                    text: "关闭",
                    click: function () {
                        $(this).dialog("close");
                    }
                }]
            });

            // Link to open the dialog
            $("#dialog-link").click(function (event) {
                $("#dialog").dialog("open");
                event.preventDefault();
            });

            // Hover states on the static widgets
            $("#dialog-link").hover(function () {
                $(this).addClass("ui-state-hover");
            }, function () {
                $(this).removeClass("ui-state-hover");
            });

        });
    </script>
    <jsp:include page="../common/mycss.jsp" />
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">
            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <jsp:include page="../common/title.jsp" />
            </div>
            <div class="lyear-layout-sidebar-scroll">
                <jsp:include page="../common/menu.jsp" />
            </div>
        </aside>
        <!--End 左侧导航-->
        <jsp:include page="../common/top.jsp" />
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                                <h5>班级管理&nbsp;&gt;&nbsp;班级信息添加&nbsp;&nbsp;
                                    <span style="color:#000;">(目前已有<s:property value="validCount"/>条有效班级信息)
			</span>
                                </h5>
                            </div>
                            <div class="card-body">
                                <div id="accordion">
                                    <div class="frame">
                                        目前存在如下班级:
                                        <br><br>

                                        <table class="datalist">
                                            <s:iterator value="validGrades" status="st">
                                                <s:if test="#st.index % 8 == 0">
                                                    <tr>
                                                </s:if>
                                                <td>
                                                    <a href="#">
                                                        <s:property value="year"/>
                                                        届<s:property value="name"/> （
                                                        <s:property value="classID"/>
                                                        ）班
                                                    </a></td>
                                                <s:if test="#st.index % 8 == 7">
                                                    <tr></tr>
                                                </s:if>
                                            </s:iterator>
                                        </table>

                                        <br>
                                        <br>
                                        <a href="#" id="dialog-link" class="ui-state-default ui-corner-all"><button id="selectDeleteBtn">选择删除</button></a> <br/>
                                        <p style="color:red">（说明：只能删除没有关联学生信息的班级信息）</p>
                                        <br>
                                        <hr>
                                        <div>
                                            <form id="form1" name="form1" method="post" action="gradeSetUpRegister.action">
                                                <table class="datalist">
                                                    <tr>
                                                        <th align="right"><strong>班级编号</strong></th>
                                                        <td><input type="text"
                                                                   name="grade.bianHao" id="bianHao" readonly="readonly" class="inputStyle"/> <input
                                                                type="button"
                                                                name="autoExec" id="autoExec" class="autoExec" value="自动激活"/></td>
                                                    </tr>
                                                    <tr>
                                                        <th align="right"><strong>年级、届</strong></th>
                                                        <td><input type="text"
                                                                   name="grade.year" id="year" value='<s:property value="maxYear"/>'
                                                                   class="inputStyle"/><span id="yearError" class="ErrorStyle"></span></td>
                                                    </tr>
                                                    <tr>
                                                        <th align="right"><strong>班级序号</strong></th>
                                                        <td><input type="text"
                                                                   name="grade.classID" id="classID" value='<s:property value="classesCount"/>'
                                                                   class="inputStyle"/><span id="classIDError" class="ErrorStyle"></span></td>
                                                    </tr>
                                                    <tr>
                                                        <th align="right"><strong>专&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;业</strong></th>
                                                        <td><input type="text"
                                                                   name="grade.name" id="name" class="inputStyle"/><span id="nameError" class="ErrorStyle"></span></td>
                                                    </tr>
                                                    <tr>
                                                        <th align="right"><strong>班 &nbsp;主&nbsp; 任</strong></th>
                                                        <td><select name="grade.adviser" id="adviser"
                                                                    id="select">
                                                            <s:iterator value="subTeachers">
                                                                <option value="<s:property value="bianHao" />"><s:property value="name"/></option>
                                                            </s:iterator>
                                                        </select></td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan="2" align="center"><input type="button"
                                                                                              name="save" id="save" value="注册"/> <input type="reset"
                                                                                                                                        name="button3"
                                                                                                                                        id="button3"
                                                                                                                                        value="取消"/>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </form>
                                        </div>
                                    </div>
                                </div>

                                <div id="dialog" title="选择删除">
                                    <form id="form2" name="form2" method="post" action="gradeDelete.action">
                                        <s:iterator value="gradesEnableDel">
                                            <input type="checkbox" name="gradeDel"
                                                   value="<s:property value="bianHao" />"/>&nbsp;<s:property
                                                value="year"/>届<s:property value="name"/>（<s:property value="classID"/>）班
                                            <br/>
                                            <hr/>
                                        </s:iterator>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="删除"/>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>
</body>
</html>
